<template>
  <view class="more-settings">
    <view class="more-settings-content">
      <view class="settings-con">
        <view class="settings-item">
          <view class="settings-item-form">
            <nut-form>
              <nut-cell
                is-link
                title="协助管理"
                v-if="false"
              >
                <template #desc>
                  <view class="desc">
                    <text v-if="false">666</text>
                    <text>未设置</text>
                  </view>
                </template>
              </nut-cell>
              <nut-cell
                is-link
                center
                @click="addWhitelistUser"
              >
                <template #title>
                  <view class="whitelist-title">
                    <text>白名单</text>
                    <text>白名单成员不参与打卡</text>
                  </view>
                </template>
                <template #desc>
                  <view
                    class="desc"
                    :class="{ active: whitelistUsers.length > 0 }"
                  >
                    <template v-if="whitelistUsers.length > 0">
                      <text
                        v-for="(itm, idx) in whitelistUsers"
                        :key="idx"
                      >
                        {{ itm.nickName }}{{ idx < whitelistUsers.length - 1 ? "，" : "" }}
                      </text>
                    </template>
                    <text v-else>未设置</text>
                  </view>
                </template>
              </nut-cell>
              <nut-cell
                class="switch-cell"
                is-link
                center
                v-if="false"
              >
                <template #title>
                  <view class="whitelist-title">
                    <text>提醒</text>
                    <text>对打卡人员发送消息提醒打卡</text>
                  </view>
                </template>
                <template #desc>
                  <view class="desc"> </view>
                </template>
              </nut-cell>
              <nut-cell>
                <template #title>
                  <view class="desc">
                    <text>范围外打卡记录地点异常</text>
                  </view>
                </template>
                <template #link>
                  <nut-switch v-model="outScopeFlag" />
                </template>
              </nut-cell>
              <nut-cell center>
                <template #title>
                  <view class="whitelist-title">
                    <text>外出打卡记录同步</text>
                    <text>非全天的请假需要按时打卡，否则将记录异常</text>
                  </view>
                </template>
                <template #link>
                  <nut-switch v-model="outSyncFlag" />
                </template>
              </nut-cell>
              <nut-cell
                center
                is-link
                v-if="false"
              >
                <template #title>
                  <view class="whitelist-title">
                    <text>防止多台设备打卡</text>
                    <text>避免打卡人员打卡作弊</text>
                  </view>
                </template>
                <template #desc>
                  <view class="desc">
                    <text v-if="false">666</text>
                    <text>未设置</text>
                  </view>
                </template>
              </nut-cell>
              <nut-cell
                center
                is-link
                @click="userCheckInManagement"
              >
                <template #title>
                  <view class="whitelist-title">
                    <text>成员打卡设备管理</text>
                    <text>管理员可查看、解绑创建的规则中成员设备</text>
                  </view>
                </template>
                <!-- <template #desc>
                  <view class="desc">
                    <text v-if="false">666</text>
                    <text>未设置</text>
                  </view>
                </template> -->
              </nut-cell>
            </nut-form>
          </view>
        </view>
      </view>
    </view>
    <view class="logo-bottom">
      <img
        src="https://img.alicdn.com/imgextra/i2/1034622205/O1CN01ROtCca1S9wNLeJ6zx_!!1034622205.png"
        alt=""
      />
    </view>
    <view
      class="add-schedule-btn"
      @click="submit"
    >
      <nut-button color="#1E74FD"> 保存 </nut-button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { navigateTo, useDidShow } from "@tarojs/taro";
import { userInfoStore } from "@/stores/userInfoStore";
import { addAttendanceRules, getWifiLists } from "@/api/index";
import Taro from "@tarojs/taro";
const store = userInfoStore();
const checked = ref(true);
const whitelistDeptIds = ref([]);
const whitelistUserIds = ref([]);
const selectUsers = ref([]);
const whitelistUsers = ref([]);
const selectUserNames = ref([]);
const outScopeFlag = ref(0);
const outSyncFlag = ref(0);
useDidShow(() => {
  whitelistDeptIds.value = [];
  whitelistUserIds.value = [];
  selectUserNames.value = [];
  let storeSelectDeptIds = JSON.parse(JSON.stringify(store.whitelistUserIds));
  selectUsers.value = storeSelectDeptIds;
  storeSelectDeptIds.forEach((item: any) => {
    whitelistDeptIds.value.push(item.deptId);
    whitelistUserIds.value.push(item.userId);
    selectUserNames.value.push(item.deptName);
  });
  whitelistDeptIds.value = [...new Set(whitelistDeptIds.value)];
  whitelistUsers.value = selectUsers.value; //白名单人员
});
const userCheckInManagement = () => {
  navigateTo({
    url: "/components/deptStaffSelectDevice/index",
  });
};
const addWhitelistUser = () => {
  navigateTo({
    url:
      "/components/deptStaffSelect/index?userIds=" +
      whitelistUserIds.value +
      "&ids=" +
      whitelistDeptIds.value +
      "&type=whitelist",
  });
};
// 提交
const submit = () => {
  //   whitelistUsers.value = selectUsers.value; //白名单人员
  whitelistUsers.value.map((item: any) => {
    item.moreFlag = 0;
  });
  store.whitelistUserData = {
    whitelistUsers: whitelistUsers.value,
    outScopeFlag: outScopeFlag.value ? 1 : 0, //范围外打卡记录地点异常
    outSyncFlag: outSyncFlag.value ? 1 : 0, //外出打卡记录同步
  };
  // 返回上一级
  Taro.navigateBack();
};
</script>

<style lang="less">
@import url("./index.less");
@import "@/assets/css/index.less";
</style>
